package com.guohui.boot1.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 全局异常配置，用于处理控制器内部发生异常时
 * @author GUOHUI
 * @version V1.0
 * @date 2017年8月8日 下午1:22:20
 */
@ControllerAdvice
public class GlobalExceptionHandler {

  private Logger logger = LoggerFactory.getLogger(getClass());
  
  private static final String IN_MESSAGE = "in controller exception:";
  
  @ExceptionHandler(value=Exception.class)
  @ResponseBody
  @ResponseStatus(value=HttpStatus.INTERNAL_SERVER_ERROR)
  public String handleException(HttpServletRequest request,Exception ex) {
    String msg = IN_MESSAGE+ex.getMessage();
    logger.debug(msg);
    return msg;
  }
  
}
